import $ from '@/utils/requset'
const URL = 'http://47.102.159.133:8888/api/private/v1'

// 首页数据
const getHomeApi = () => $.getAxios('list')
//角色列表数据
const getListApi = () => $.getAxios(URL + '/roles')
//角色添加
const getAddApi = ({ roleDesc, roleName }) =>
  $.postAxios(URL + '/roles', { roleDesc, roleName })
//删除商品
const deRoles = (id = null) => $.delAxios(URL + '/roles/' + id)
//编辑角色
const bianjiApi = ({ id, roleDesc, roleName }) =>
  $.putAxios(URL + '/roles/' + id, { roleDesc, roleName })

//权限列表
const gitLimits = () => $.getAxios(URL + '/rights/list')
// 登录
const postLogin = ({
  tel = null,
  password = null,
  yzm = null,
  sms = null,
} = {}) => $.postAxios('login', { tel, password, yzm, sms })

//实验数据
const postSyan = ({ username = null, password = null } = {}) =>
  $.postAxios(URL + '/login', { username, password })
//用户数据列表
const getsyan = ({ pagenum = null, pagesize = null }) =>
  $.getAxios(URL + '/users', { pagenum, pagesize })
// 添加用户
const postuser = ({
  username = null,
  password = null,
  email = null,
  mobile = null,
} = {}) => $.postAxios(URL + '/users', { username, password, email, mobile })
// 删除单个用户
const deleteUser = id => $.deleteAxios(URL + `/users/${id}`)
// const deleteRigthtsRoles = (id) => $.deleteAxios(`/roles/${id}`)

//订单数据列表
const DingList = ({ pagenum = null, pagesize = null }) =>
  $.getAxios(URL + '/orders', { pagenum, pagesize })

//获取商品列表
const getgoods =({query=null,pagenum =null,pagesize=null})=>$.getAxios(URL+"/goods",{query,pagenum,pagesize})

// 分类数据
const getParamList = ({pagenum =null,pagesize=null}) => $.getAxios(URL+"/categories",{pagenum,pagesize})

// 添加分类
const postParamList = ({cat_pid = null,cat_name = null,cat_level = null}) => $.postAxios(URL+"/categories",{"cat_pid": cat_pid,"cat_name": cat_name, "cat_level": cat_level})
// 编辑分类
const putParamList = ({id=null,name=null}) => $.putAxios(URL+`/categories/${id}`,{cat_name:name})
// 删除分类
const delParamList = (id) => $.deleteAxios(URL+`/categories/${id}`)

// 获取数据报表数据
const getreports = () => $.getAxios(URL+"/reports/type/1")


//删除商品
const delgoods =(id=null) =>$.delAxios(URL+"/goods/"+id)

//请求添加商品中分类 http://47.102.159.133:8888/api/private/v1/categories
const getCate =()=>$.getAxios(URL+"/categories")

//添加商品goods
const postGoods = ({goods_name=null,goods_cat=null,goods_price=null,goods_number=null,goods_weight=null,goods_introduce=null,pics=null,attrs=null}={}) => $.postAxios(URL+"/goods",{goods_name,goods_cat,goods_price,goods_number,goods_weight,goods_introduce,pics,attrs})

//分类详情
const getCategories = ({id=null,sel=null}) =>$.getAxios(URL+"/categories/"+id+"/attributes/",{sel})

//添加动态属性 静态属性
const postCategories =({id=null,sel=null,attr_name=null,attr_sel=null,attr_vals=null,attr_write=null}) =>$.postAxios(URL+"/categories/"+id+"/attributes/",{attr_name,attr_sel,attr_vals,attr_write})

//删除分类属性   categories/:id/attributes/:attrid
const delCate=({id=null,attrid=null})=>$.delAxios(URL+"/categories/"+id+"/attributes/"+attrid)

//修改动态属性 静态属性                                                                                                                                                              categories/:id/attributes/:attrId
const putCategories =({id=null,attrid=null,attr_name=null,attr_sel=null,attr_vals=null,attr_write=null}) =>$.putAxios(URL+"/categories/"+id+"/attributes/"+attrid,{attr_name,attr_sel,attr_vals,attr_write})

//查询用户
const SearchUser = (id) => $.getAxios(URL + `/users/${id}`)

//编辑用户
const ChangeUser = ({id,email,mobile}) => $.putAxios(URL + '/users/' + id,{email,mobile})


// 修改用户状态
const changUserStateRequest = (uId,type) => $.putAxios(URL + `/users/${uId}/state/${type}`)


export default {
    // 首页数据
    getHomeApi,
    //登录
    postLogin,
    // 
    postSyan,
    // 获取用户列表
    getsyan,

  //添加用户
  postuser,

  //角色列表
  getListApi,
  //角色添加
  getAddApi,
  //删除商品
  deRoles,
  //编辑权限
  bianjiApi,
  //权限列表
  gitLimits,

//  添加中的分类
  getCate,
//  添加商品
  postGoods,

  //分类参数
  getCategories,

//  添加属性
  postCategories,

//  删除分类
  delCate,

//  修改参数
  putCategories,
    //删除用户
    deleteUser,

    //订单数据列表
    DingList,

    //获取商品列表
    getgoods,

    //删除商品
    delgoods,

    //查询用户
    SearchUser,

    //编辑用户
    ChangeUser,

    // 修改用户状态
    changUserStateRequest,

    // 数据报表数据
    getreports,

    // 分类数据
    getParamList,
    // 添加分类
    postParamList,
    // 编辑分类
    putParamList,
    // 删除分类
    delParamList,

}
